package d1120;

import java.util.ArrayList;
import java.util.Collection;

//集合的遍历  集合中的元素是对象
public class Demo02 {
    public static void main(String[] args) {
        Collection coll =new ArrayList();

        //集合中添加元素


        coll.add(new Student("刘备","1001"));
        coll.add(new Student("关羽","1001"));
        coll.add(new Student("张飞","1001"));
        coll.add(new Student("赵云","1001"));
        coll.add(new Student("诸葛亮","1001"));
        //遍历该集合
      /*  for (Object stu:coll){
            System.out.println(stu);
        }*/
        //迭代器来遍历集合
        //第一步：获得迭代器
     /*   Iterator it  =coll.iterator();
        while(it.hasNext()){
            System.out.println(it.next());

        }*/
      /*  it.hasNext();
         Object obj=it.next();
        System.out.println(obj);
        System.out.println(it.next());*/
        //集合的方法  lambda方式的forEach()
        coll.forEach((s)->{
            System.out.println(s);
        });


        }
    }

